package history.hot100;

// 309. 最佳买卖股票时机含冷冻期
public class LeetCode_309 {
    public int maxProfit(int[] prices) {
        if (prices == null || prices.length ==0) return 0;
        int n = prices.length;
        int [][]state = new int[n][3];
        state[0][0] = -prices[0];
        for (int i = 1; i < n; ++i) {
            state[i][0] = Math.max(state[i-1][0], state[i-1][2]-prices[i]);
            state[i][1] = state[i-1][0]+prices[i];
            state[i][2] = Math.max(state[i-1][1], state[i-1][2]);
        }
        return Math.max(state[n-1][1], state[n-1][2]);
    }
}
